<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="线别">
              <a-input placeholder="请输入线别" v-model="queryParam.query5"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="制令单">
              <a-select style="width:100%" v-model="queryParam.baseRownum" option-label-prop="label" allowClear showSearch  :filterOption="filterOption">
                <a-select-option v-for="d in instrlist" :value="d.id" :label="d.commandbillCode">
                  {{ d.commandbillCode }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="查询区间">
                <j-date placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.createBy" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.updateBy" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="PCB二维码">
                <a-input placeholder="请输入PCB二维码" v-model="queryParam.id"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="物料代码">
                <a-input placeholder="请输入物料代码" v-model="queryParam.productCode"></a-input>
              </a-form-item>
            </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" icon="download" @click="handleExportXls('PCB使用报表')" style="margin-left: 8px">导出</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <!--<div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
        <!--<i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
        <!--<a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--</div>-->
      <!--<span style="font-size:15px;font-weight:bold;">产线统计：{{tjstr}}</span>-->
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :scroll="{ x:true}"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="pcbedit(record)">编辑</a>
          <!--<a @click="handleEdit(record)">编辑</a>-->

          <!--<a-divider type="vertical" />-->
          <!--<a-dropdown>-->
            <!--<a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
            <!--<a-menu slot="overlay">-->
              <!--<a-menu-item>-->
                <!--<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
                  <!--<a>删除</a>-->
                <!--</a-popconfirm>-->
              <!--</a-menu-item>-->
            <!--</a-menu>-->
          <!--</a-dropdown>-->
        </span>

      </a-table>
    </div>

    <PcbUseEditModal ref="modalForm1" @ok="modalFormOk"></PcbUseEditModal>
  </a-card>
</template>

<script>

  import { httpAction,getAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import '@/assets/less/TableExpand.less'
import JDate from '@/components/jeecg/JDate.vue'
  import PcbUseEditModal from './PcbUseEditModal'

export default {
    name: 'PcbUseReportList',
    mixins: [JeecgListMixin],
    components: {
      JDate,
      PcbUseEditModal
    },
    data () {
        return {
          instrlist:{},
          showmodal:false,
            description: 'PCB使用报表',
            // 表头
            columns: [
                {
                    title: '序号',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: 'center',
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1
                    }
                },
              {
                title: '产线',
                align: 'center',
                dataIndex: 'query5'
              },
              {
                title: '制令单',
                align: 'center',
                dataIndex: 'baseRownum'
              },
                {
                    title: '物料代码',
                    align: 'center',
                    dataIndex: 'productCode',
                    scopedSlots: {
                      customRender: 'productCode'
                    },
                },
                {
                    title: '物料名称',
                    align: 'center',
                    dataIndex: 'productName'
                },
              {
                title: '开始时间',
                align: 'center',
                dataIndex: 'createTime'
              },
                {
                    title: 'PCB二维码',
                    align: 'center',
                    dataIndex: 'id'
                },
                {
                    title: '数量',
                    align: 'center',
                    dataIndex: 'inwareNum'
                },
                {
                    title: '单位',
                    align: 'center',
                    dataIndex: 'unit'
                },
              {
                title: 'AOI结果',
                align: 'center',
                dataIndex: 'query1'
              },
              {
                title: 'AOI结果描述',
                align: 'center',
                dataIndex: 'query3'
              },
              {
                title: 'SPI结果',
                align: 'center',
                dataIndex: 'query2'
              },
              {
                title: 'SPI结果描述',
                align: 'center',
                dataIndex: 'query4'
              },
                {
                    title: '操作人',
                    align: 'center',
                    dataIndex: 'createBy'
                },
              {
                title: '操作',
                dataIndex: 'action',
                align: "center",
                scopedSlots: {
                  customRender: 'action'
                },
              }
            ],
            url: {
                list: '/storage/reportapi/pcbUseReport',
              exportXlsUrl: "/storage/reportapi/exportPcbXls",
                instrlist:'/produce/mesCommandbillInfo/list'
            },
            dictOptions: {},
          tjstr:''
        }
    },
    computed: {

    },
    methods: {
      initDictConfig () {
        let url = this.url.instrlist+"?pageSize=1000&pageNo=1";
        var data={};
        getAction(url,data).then((res)=>{
          if(res.success){
            this.instrlist = res.result.records;
          }else{
//              this.$message.warning(res.message);
          }
        })
      },
//      mysearchQuery() {
//        this.myloadData(1);
//      },
      myloadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            console.log(res);
            this.dataSource = res.result.list.records;
            this.ipagination.total = res.result.list.total;
            this.tjstr = res.result.tjstr;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      filterOption(input, option) {
        return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      },
      pcbedit(record){
        this.$refs.modalForm1.init(record);
        this.$refs.modalForm1.title = "编辑";
        this.$refs.modalForm1.disableSubmit = false;
      }
    }
}
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
